package com.qubuyer.base.activity

import android.os.Bundle
import com.qubuyer.R
import com.qubuyer.core.app.BaseFragment
import com.qubuyer.core.app.MVVMActivity
import com.qubuyer.core.framework.BaseViewModel
import com.qubuyer.databinding.ActivityHostBinding

abstract class HostActivity<VM : BaseViewModel> : MVVMActivity<ActivityHostBinding, VM>() {

    override fun onDataBind(dataBinding: ActivityHostBinding) {

    }

    override val layoutId: Int
        get() = R.layout.activity_host

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        dataBinding.titleBar.setOnNaviClick { onBackPressed() }
        addContentFragment(contentFragment(), R.id.flContent)
        fragmentTitle.observe(this, {
            dataBinding.titleBar.setTitle(it)
        })
    }

    abstract fun contentFragment(): BaseFragment

    override fun onBackPressed() {
        hideKeyBord()
        if(showingFragment == originFragment){
            finish()
            return
        }
        if (showingFragment?.onBackPressed() == true) {
            return
        }
        super.onBackPressed()
    }
}